<?
session_start();
include_once("secure/connect.php");
include_once("secure/functions.php");
if (!$_SESSION['logged'])
	{
	print "SESSION FERMEE";
	die;
	}

$sql_look_fiche_loc="SELECT id, type_fact, etat, etat_facture, modalite_facture FROM fiches_loc WHERE id='".$_GET['id_fiche_loc']."'";
$res_look_fiche_loc=mysql_query($sql_look_fiche_loc,$db);
$ligne_look_fiche_loc=mysql_fetch_assoc ($res_look_fiche_loc);

if ($_POST['Submit_etat']){
if ($_POST['visa'])
	
	{
	if ($_POST['commentaire']=="commentaire facultatif") {$_POST['commentaire']="";}
	if ($_POST['type_fact'] !=$ligne_look_fiche_loc['type_fact']) 
		{
		$sql_update_fiche_loc="UPDATE fiches_loc SET type_fact='".$_POST['type_fact']."' WHERE id='".$_GET['id_fiche_loc']."'";
		$sql_insert_log = 'INSERT INTO `fiches_loc_types_log` ( `id_fiches_loc`, `id_fiches_loc_type`, `date`, `commentaire`, `id_admin`) VALUES (\''.$_GET['id_fiche_loc'].'\', \''.$_POST['type_fact'].'\', NOW(),  \''.$_POST['commentaire'].'\', \''.$_POST['visa'].'\');';

		}
		
	if ($_POST['etat'] != $ligne_look_fiche_loc['etat'])
		{
			if ($_POST['etat']==7)
			{
			desactive_fiche($_GET['id_fiche_loc'], $db);
			}
			if ($_POST['etat']==2 && ($_POST['fallbackDay']||$_POST['fallbackDate']))
			{
				if ($_POST['fallbackDay'])
				{
				$dateFallback=date("Y-m-d H:i:s",time()+(24*3600*$_POST['fallbackDayNumber']));
				}
				elseif ($_POST['fallbackDate'])
				{
				$dateFallback=$_POST['dateFallback_Y']."-".$_POST['dateFallback_m']."-".$_POST['dateFallback_d']." ".$_POST['dateFallback_H'].":".$_POST['dateFallback_i'].":00";
				}
				$_POST['commentaire']=$_POST['commentaire']." (repasser en devis le ".$dateFallback.")";
				$sql_update_fiche_loc="UPDATE fiches_loc SET auto_fallback='".$dateFallback."' WHERE id='".$_GET['id_fiche_loc']."'";
				mysql_query($sql_update_fiche_loc,$db);
			}
		$sql_update_fiche_loc="UPDATE fiches_loc SET etat='".$_POST['etat']."' WHERE id='".$_GET['id_fiche_loc']."'";
		$sql_insert_log = 'INSERT INTO `fiches_loc_etats_log` ( `id_fiches_loc`, `id_fiches_loc_etats`, `date`, `commentaire`, `id_admin`) VALUES (\''.$_GET['id_fiche_loc'].'\', \''.$_POST['etat'].'\', NOW(),  \''.$_POST['commentaire'].'\', \''.$_POST['visa'].'\');';

	
		}
		
	if ($_POST['modalite_facture'] != $ligne_look_fiche_loc['modalite_facture'])
		{
		$sql_update_fiche_loc="UPDATE fiches_loc SET modalite_facture='".$_POST['modalite_facture']."' WHERE id='".$_GET['id_fiche_loc']."'";
		$sql_insert_log = 'INSERT INTO `fiches_loc_modalite_facture_log` ( `id_fiches_loc`, `id_fiches_loc_modalite_facture`, `date`, `commentaire`, `id_admin`) VALUES (\''.$_GET['id_fiche_loc'].'\', \''.$_POST['modalite_facture'].'\', NOW(),  \''.$_POST['commentaire'].'\', \''.$_POST['visa'].'\');';

		}
	
	mysql_query($sql_update_fiche_loc,$db);
	mysql_query($sql_insert_log,$db);
	
	}
	else 
	{
		$fond_cellule_visa=true;
	}
}



$sql_look_fiche_loc="SELECT id, type_fact, etat, etat_facture, modalite_facture FROM fiches_loc WHERE id='".$_GET['id_fiche_loc']."'";
$res_look_fiche_loc=mysql_query($sql_look_fiche_loc,$db);
$ligne_look_fiche_loc=mysql_fetch_array ($res_look_fiche_loc);


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Modifier les conditions de facturation</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
.droite {
	text-align: right;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: x-small;
}
body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: x-small;
}
.buton {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: x-small;
}
-->
</style>
</head>

<body>
<? if ($ligne_look_fiche_loc['id']==$_GET['id_fiche_loc'] && $ligne_look_fiche_loc['id']) { ?>

<form action="" method="post" id="mise_a_jour"><input type="hidden" name="Submit_etat" value="1">
		<table width="489" border="1">
        		<tr>
        		  <td>1.</td>
        		  <td colspan="2" <? if ($fond_cellule_visa) {echo 'bgcolor="#FF0000"';}?>><textarea name="commentaire" cols="50" rows="3" id="commentaire">commentaire facultatif</textarea>
                    <br>
                    <? mk_list_table("visa",0,"SELECT id, user FROM admin WHERE active= '1' ORDER BY user", "id", "user", $db, TRUE);  ?>
VISA obligatoire</td>
   		  </tr>
               	  <td rowspan="3">2.</td>
               	  <td width="142">type contrat
           	      </td>
                    <td width="331" align="left"><? mk_list_table_autosubmit("type_fact",$ligne_look_fiche_loc['type_fact'],"SELECT id, nom FROM fiches_loc_types WHERE active ='1' ORDER BY id", "id", "nom", $db, FALSE);  ?></td>
                </tr>
            	<tr><td >&eacute;tat mat&eacute;riel</td>
        				<td align="left"><? mk_list_table_autosubmit("etat",$ligne_look_fiche_loc['etat'],"SELECT id, nom FROM fiches_loc_etats WHERE active= '1' ORDER BY id", "id", "nom", $db, FALSE);  ?>
       				      
       				      <br>
       				      passer de r&eacute;serv&eacute; &agrave; devis:<br>
       				      <input type="radio" name="fallbackDay" value="1">dans <input name="fallbackDayNumber" type="text" size="2" maxlength="3"> jours<br>
       				      <input type="radio" name="fallbackDate" value="1"> le
			            <? dates_select_trois(date("Y-m-d"), date("Y")-1, date("Y")+1, "dateFallback");?> à <? heures_2_select(15, "dateFallback",  date("H:i:s")); ?></td>
		  </tr>

        		<tr>
        		  <td>modalit&eacute; paiement</td>
        		  <td align="left"><? mk_list_table_autosubmit("modalite_facture",$ligne_look_fiche_loc['modalite_facture'],"SELECT id, nom FROM fiches_loc_modalite_facture WHERE active= '1' ORDER BY id", "id", "nom", $db, FALSE);  ?></td>
   		  </tr>
  </table>
</form>
10 derniers états:<br>
<?
$sql="SELECT log.date, log_nom.nom, a.user, log.commentaire FROM fiches_loc_etats_log log, fiches_loc_etats log_nom, admin a WHERE log.id_fiches_loc_etats=log_nom.id AND log.id_admin=a.id AND id_fiches_loc='".$_GET['id_fiche_loc']."' ORDER BY date DESC LIMIT 0, 10";
$res=mysql_query($sql,$db);
while($ligne=mysql_fetch_assoc ($res))
	{
	echo $ligne['date']." | ".$ligne['nom']." | ".$ligne['user']." | ".$ligne['commentaire']."<br>";
	}

?>
<hr>
5 derni&egrave;res modalités de paiement:
<br>
<?
$sql="SELECT log.date, log_nom.nom, a.user, log.commentaire FROM fiches_loc_modalite_facture_log log, fiches_loc_modalite_facture log_nom, admin a WHERE log.id_fiches_loc_modalite_facture=log_nom.id AND log.id_admin=a.id AND id_fiches_loc='".$_GET['id_fiche_loc']."' ORDER BY date DESC LIMIT 0, 5";
$res=mysql_query($sql,$db);
while($ligne=mysql_fetch_assoc ($res))
	{
	echo $ligne['date']." | ".$ligne['nom']." | ".$ligne['user']." | ".$ligne['commentaire']."<br>";
	}

?>
<hr>
5 derniers types de contrat:
<br>
<?
$sql="SELECT log.date, log_nom.nom, a.user, log.commentaire FROM fiches_loc_types_log log, fiches_loc_types log_nom, admin a WHERE log.id_fiches_loc_type=log_nom.id AND log.id_admin=a.id AND id_fiches_loc='".$_GET['id_fiche_loc']."' ORDER BY date DESC LIMIT 0, 5";
$res=mysql_query($sql,$db);
while($ligne=mysql_fetch_assoc ($res))
	{
	echo $ligne['date']." | ".$ligne['nom']." | ".$ligne['user']." | ".$ligne['commentaire']."<br>";
	}

?>
<? }
else
{
?>
FICHE INEXISTANTE!
<?
}
?>
</body>
</html>
